home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / e / modulesmc.lha / ModulesMC1 / qstringf20.e < prev    next >
Encoding:
Text File  |  1994-11-09  |  2.1 KB  |  125 lines

  1. OPT MODULE
  2. EXPORT PROC stringf(str,format,listptr=NIL:PTR TO LONG)
  3.    MOVEA.L str,A0
  4.    MOVE.L A0,A6
  5.    MOVEA.L format,A1
  6.    MOVEA.L listptr,A2
  7. nxt:
  8.    MOVE.B (A1)+,(A0)+
  9.    BEQ.S  done
  10.    CMPI.B  #"%",-1(A0)
  11.    BNE.S nxt
  12.    MOVE.B (A1)+,(A0)+
  13.    CMPI.B  #"l",-1(A1)
  14.    BEQ.S gotl
  15.    CMPI.B  #"s",-1(A1)
  16.    BNE.S nxt
  17.    SUBQ.W #2,A0      /* eat the %s    */
  18.    MOVEA.L (A2)+,A3     /* must be a string pointer  */
  19. dcopy:
  20.    MOVE.B  (A3)+,(A0)+    /* copy byte  */
  21.    BNE.S dcopy
  22.    SUBQ.W  #1,A0      /* write over 0  */
  23.    BRA.S  nxt
  24.  
  25. done:
  26.    SUBA.L A6,A0
  27.    SUBQ.L #1,A0     /* length  */
  28.    EXG A6,A0        /* A0 points to str, A6 to length  */
  29.    CMPA.W -4(A0),A6      /* compare with maxlength  */
  30.    BHI.S toolong
  31.    MOVE.W A6,-2(A0)      /* equivalent to SetStr()  */
  32. toolong:
  33.    MOVE.L A6,D1
  34.    MOVE.L A0,D0
  35.    BRA endstringf
  36.  
  37. gotl:
  38.    MOVE.B (A1)+,D0
  39.    MOVE.B D0,(A0)+
  40.    CMPI.B #"d",D0
  41.    BEQ.S gotdec
  42.    CMPI.B #"x",D0
  43.    BEQ gothex
  44.    CMPI.B #"c",D0
  45.    BEQ.S gotchar
  46.    CMPI.B #"b",D0
  47.    BNE.S nxt
  48.    SUBQ.W #3,A0    /* eat %lb  */ /* bin routine starts here  */
  49.    MOVE.L (A2)+,D0
  50.    BEQ.S binzero
  51.    MOVEQ #31,D1
  52. next0:
  53.    BTST  D1,D0
  54.    DBNE D1,next0
  55. nextbit:
  56.    BTST D1,D0
  57.    BEQ.S bit0
  58.    MOVE.B #"1",(A0)+
  59.    BRA.S bit1
  60. bit0:
  61.    MOVE.B #"0",(A0)+
  62. bit1:
  63.    DBRA D1,nextbit
  64.    BRA nxt
  65.  
  66. binzero:
  67.    MOVE.B #"0",(A0)+
  68.    BRA nxt
  69.  
  70. gotchar:
  71.    SUBQ.W #3,A0
  72.    MOVE.L (A2)+,D0
  73.    MOVE.B D0,(A0)+
  74.    BRA nxt
  75.  
  76. gotdec:
  77.    SUBQ.W #3,A0
  78.    MOVE.L (A2)+,D0
  79.    SUBA.W  #14,A7
  80.    MOVEA.L A7,A3
  81.    MOVE.L D0,D2
  82.    BGE.S repeat
  83.    NEG.L D0
  84. repeat:
  85.    MOVEQ  #0,D1
  86.    LONG $4C7C0401,$A   /* DIVU.L #10,D1:D0    */
  87.    ADDI.B #"0",D1
  88.    MOVE.B D1,(A3)+
  89.    TST.L D0
  90.    BGT.S repeat
  91.    TST.L D2
  92.    BGE.S notneg
  93.    MOVE.B #"-",(A3)+
  94. notneg:
  95.    MOVE.B  -(A3),(A0)+
  96.    CMPA.L  A3,A7
  97.    BLT.S notneg
  98.    ADDA.W #14,A7
  99.    BRA nxt
  100.  
  101. gothex:
  102.    MOVE.L (A2)+,D0
  103.    SUBQ.W #3,A0
  104.    MOVEA.L A7,A3
  105.    SUBA.W  #14,A3
  106.    MOVEQ #-1,D2
  107. nextltr:
  108.    MOVE.B D0,D1
  109.    ANDI.B #$0F,D1
  110.    ADDI.B #48,D1
  111.    CMPI.B #57,D1
  112.    BLE.S around
  113.    ADDQ.B #7,D1
  114. around:
  115.    MOVE.B D1,(A3)+
  116.    LSR.L #4,D0
  117.    DBEQ D2,nextltr
  118.    NOT.L D2
  119. loadstr:
  120.    MOVE.B -(A3),(A0)+    /* reverse buffer  */
  121.    DBF D2,loadstr
  122.    BRA nxt
  123. endstringf:
  124. ENDPROC D0
  125.